<template>
  <div class="todo-list">
    <h1>大美女吴航自律计划</h1>
    <div class="add-todo">
      <input 
        v-model="newTodoTitle" 
        @keyup.enter="addTodo"
        placeholder="请输入您的待办事项..."
      >
      <button @click="addTodo">添加</button>
    </div>
    <div class="todos">
      <TodoItem
        v-for="(todo, index) in todos"
        :key="index"
        :title="todo.title"
        :completed="todo.completed"
        @update:completed="updateTodoCompleted(index, $event)"
        @remove-todo="removeTodo(index)"
      />
    </div>
  </div>
</template>

<script>
import TodoItem from './TodoItem.vue'

export default {
  name: 'TodoList',
  components: {
    TodoItem
  },
  data() {
    return {
      todos: [

      ],
      newTodoTitle: ''
    }
  },
  methods: {
    addTodo() {
      if (this.newTodoTitle.trim()) {
        this.todos.push({
          title: this.newTodoTitle.trim(),
          completed: false
        });
        this.newTodoTitle = '';
      }
    },
    removeTodo(index) {
      this.todos.splice(index, 1);
    },
    updateTodoCompleted(index, completed) {
      this.todos[index].completed = completed;
    }
  }
}
</script>

<style scoped>
.todo-list {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
}

.add-todo {
  display: flex;
  margin-bottom: 20px;
}

.add-todo input {
  flex-grow: 1;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px 0 0 4px;
}

.add-todo button {
  padding: 8px 15px;
  background: #42b983;
  color: white;
  border: none;
  border-radius: 0 4px 4px 0;
  cursor: pointer;
}
</style>